class WordCard {
  final String word;
  final String wordAudio;
  final String imageFile;
  final String accent;
  final String meanCn;
  String status; // 'new' 或 'review'，表示单词在新词词库还是复习词库
  int repeatCount; // 记录单词在跟读模式中的重复次数

  WordCard({
    required this.word,
    required this.wordAudio,
    required this.imageFile,
    required this.accent,
    required this.meanCn,
    this.status = 'new',
    this.repeatCount = 0,
  });

  factory WordCard.fromJson(Map<String, dynamic> json) {
    return WordCard(
      word: json['word'],
      wordAudio: json['word_audio'],
      imageFile: json['image_file'],
      accent: json['accent'],
      meanCn: json['mean_cn'],
      status: json['status'] ?? 'new',
      repeatCount: json['repeat_count'] ?? 0,
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'word': word,
      'word_audio': wordAudio,
      'image_file': imageFile,
      'accent': accent,
      'mean_cn': meanCn,
      'status': status,
      'repeat_count': repeatCount,
    };
  }

  // 创建一个新的WordCard实例，更新状态
  WordCard copyWith({
    String? status,
    int? repeatCount,
  }) {
    return WordCard(
      word: this.word,
      wordAudio: this.wordAudio,
      imageFile: this.imageFile,
      accent: this.accent,
      meanCn: this.meanCn,
      status: status ?? this.status,
      repeatCount: repeatCount ?? this.repeatCount,
    );
  }
}
